package chapter01;

import lombok.extern.slf4j.Slf4j;

import static java.lang.Thread.sleep;

@Slf4j
public class JoinTest {
    static int r=0;
    public static void main(String[] args) throws InterruptedException {
        test1();
    }

    private static void test1() throws InterruptedException {

      log.info("开始");
        Thread t1 = new Thread(() -> {
            log.info("开始");
            try {
                sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.info("结束");
            r=10;
        }, "t1");
        t1.start();
        t1.join();// 等待线程运行结束
        log.info("结果为：{}",r);
        log.info("结束");
    }
}
